package test1;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Main1 {
	
	
	public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
		UserService userService = new UserServiceImpl();
		InvocationHandler invocationHandler = new MyInvocationHandler(userService);
		UserService userServiceProxy = 
		(UserService)Proxy.newProxyInstance(userService.getClass().getClassLoader(),  userService.getClass().getInterfaces(), invocationHandler);
		System.out.println(userServiceProxy.getName(1));
		System.out.println("=============1==============");
		System.out.println(userServiceProxy.getAge(125));
		System.out.println("====================2===============================");
		
		Class c = Class.forName("test1.UserServiceImpl");
		UserService o = (UserService) c.newInstance();
		Method m =c.getMethod("getName", int.class);
		Object result = m.invoke(o, 119);
		System.out.println("result:"+result);
	}
}
